<template>
	<view>
		<u-datetime-picker :value="Number(new Date())" @confirm="confirm" :itemHeight="80" closeOnClickOverlay
			@close="$emit('update:show', false)" @cancel="$emit('update:show', false)" :formatter="formatter"
			:show="show" :mode="mode">
		</u-datetime-picker>
	</view>
</template>

<script>
	export default {
		name: "myDatePick",
		props: {
			show:{
				default:false
			},
			mode:{
				default:"datetime"
			}
		},

		data() {
			return {};
		},
		methods: {
			formatter(type, value) {
				// console.log(type, value)
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				if (type === "hour") {
					return `${value}时`
				}
				if (type === "minute") {
					return `${value}分`
				}
				if (type === "second") {
					return `${value}秒`
				}
				return value
			},
			confirm(e) {
				console.log( uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss' ))
				if(this.mode == "date"){
					this.$emit("bindDateChange", uni.$u.timeFormat(e.value, 'yyyy-mm-dd' ))
				}else{
					this.$emit("bindDateChange", uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss' ))
				}
				this.$emit('update:show', false)
			}
		},

	}
</script>

<style>

</style>
